package cn.tedu.blockingqueue;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

public class BlockingQueueDemo2 {
    public static void main(String[] args) {
        LinkedBlockingDeque<String> queue = new LinkedBlockingDeque<>(5);
        // 队列为空, 抛出异常NoSuchElementException
//        System.out.println(queue.remove());
        // 返回null, 但是BlockingQueue不允许元素是null，所以返回null意味着队列是空的
//        System.out.println(queue.poll());

        try {
            // 产生阻塞
//            System.out.println(queue.take());

            // 定时阻塞
            System.out.println(queue.poll(5, TimeUnit.SECONDS));
        } catch (InterruptedException interruptedException) {
            interruptedException.printStackTrace();
        }
    }
}
